package me.xhy.java.springboot3.webflux.s04webfluxconfig;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.reactive.config.CorsRegistry;
import org.springframework.web.reactive.config.WebFluxConfigurer;

// @EnableWebFlux 写了这个注解，所有配置的默认值都失效。 使用 WebFluxConfig 替代
@SpringBootApplication
public class S041Application {

  public static void main(String[] args) {
    SpringApplication.run(S041Application.class, args);
  }

  @Bean
  public WebFluxConfigurer webFluxConfigurer() {

    return new WebFluxConfigurer() {
      @Override
      public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
            .allowedHeaders("*")
            .allowedMethods("*")
            .allowedOrigins("localhost");
      }

    };
  }

}
